using UnityEngine;
using System;
using System.Collections.Generic;

namespace GameCore
{
    [CreateAssetMenu(fileName = "New Content Pack", menuName = "Game/Content Pack")]
    public class ContentPack : ScriptableObject
    {
        public string packName;
        [Header("General")]
        public List<Region> regions;
        public List<Sector> sectors;
        public List<AreaConfig> areas;
        public List<Inventory> inventories;
        [Header("Backpack")]
        public List<WorldItem> bWorldItems;
        public List<GridItem> bGridItems;
        public List<Inventory> bInventories;
        [Header("Resources")]
        public List<WorldItem> rWorldItems;
        public List<GridItem> rGridItems;

        private readonly Dictionary<string, Region> _regions;
        private readonly Dictionary<string, Sector> _sectors;
        private readonly Dictionary<string, WorldItem> _worldItems = new();
        private readonly Dictionary<string, GridItem> _gridItems = new();
        private readonly Dictionary<string, Inventory> _inventories = new();

        public void Init()
        {
            foreach (var region in regions)
                PrefabFactory.AddPrefab(region.resourceID, region);
            foreach (var sector in sectors)
                PrefabFactory.AddPrefab(sector.resourceID, sector);
            foreach (var inventory in inventories)
                PrefabFactory.AddPrefab(inventory.resourceID, inventory);
            foreach (var area in areas)
                PrefabFactory.AddPrefab(area.areaID, area);
            // Backpack prefabs
            foreach (var worldItem in bWorldItems)
                PrefabFactory.AddPrefab(worldItem.resourceID, worldItem);
            foreach (var gridItem in bGridItems)
                PrefabFactory.AddPrefab(gridItem.resourceID, gridItem);
            foreach (var inventory in bInventories)
                PrefabFactory.AddPrefab(inventory.resourceID, inventory);
            // Resource prefabs
            foreach (var item in rWorldItems)
                PrefabFactory.AddPrefab(item.resourceID, item);
            foreach (var item in rGridItems)
                PrefabFactory.AddPrefab(item.resourceID, item);
        }
    }
}